import 'package:flutter/material.dart';
import 'audio_message.dart';
import 'mock.dart';
import 'text_message.dart';
import 'video_message.dart';

class ChatMessageWidget extends StatelessWidget {
  final ChatMessage message;
  const ChatMessageWidget({Key? key, required this.message}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget messageContaint(ChatMessage message) {
      switch (message.messageType) {
        case ChatMessageType.text:
          return TextMessage(message: message);
        case ChatMessageType.audio:
          return AudioMessage(
            message: message,
          );
        case ChatMessageType.video:
          return VideoMessage(
            message: message,
          );
        default:
          return SizedBox();
      }
    }

    return Padding(
      padding: EdgeInsets.only(top: 12),
      child: Row(
        mainAxisAlignment:
            message.isSender ? MainAxisAlignment.end : MainAxisAlignment.start,
        children: [
          if (!message.isSender) ...[
            CircleAvatar(
              radius: 12,
              backgroundImage: AssetImage("assets/test/girl.jpeg"),
            ),
            SizedBox(
              width: 10,
            )
          ],
          messageContaint(message),
          if (message.isSender) MessageStatusDit(status: message.messageStatus)
        ],
      ),
    );
  }
}

class MessageStatusDit extends StatelessWidget {
  final MessageStatus status;
  const MessageStatusDit({Key? key, required this.status}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Color dotColor(MessageStatus status) {
      switch (status) {
        case MessageStatus.not_sent:
          return Colors.red;
        case MessageStatus.not_view:
          return Colors.black;
        case MessageStatus.viewed:
          return Colors.green;

        default:
          return Colors.transparent;
      }
    }

    return Container(
      margin: EdgeInsets.only(left: 8),
      height: 12,
      width: 12,
      decoration:
          BoxDecoration(color: dotColor(status), shape: BoxShape.circle),
      child: Icon(
        status == MessageStatus.not_sent ? Icons.close : Icons.done,
        size: 8,
        color: Theme.of(context).scaffoldBackgroundColor,
      ),
    );
  }
}
